package spsu.cs6903.assignment3;

public class GameBoard {
	
	  
    public static final int CROSS = 1; // cross
    public static final int CIRCLE = 2; // circle
	
    Space[] board= new  Space[9];	
	
	private int winner;	
	
	public GameBoard(){
		  board[0] = new Space("Pos1", R.id.pos1);
		  board[1] = new Space("Pos2", R.id.pos2);
		  board[2] = new Space("Pos3", R.id.pos3);
		  board[3] = new Space("Pos4", R.id.pos4);
		  board[4] = new Space("Pos5", R.id.pos5);
		  board[5] = new Space("Pos6", R.id.pos6);
		  board[6] = new Space("Pos7", R.id.pos7);
		  board[7] = new Space("Pos8", R.id.pos8);
		  board[8] = new Space("Pos9", R.id.pos9);
		  
		winner = 0;
	}
	
	public void checkWinner(int p)
	{			
		 if ((p == board[0].getValue() && p == board[1].getValue() && p == board[2].getValue()) ||
			(p == board[3].getValue() && p == board[4].getValue() && p == board[5].getValue())  ||
			(p == board[6].getValue() && p == board[7].getValue() && p == board[8].getValue()))
			 setWinner(p);
		else if ((p == board[0].getValue() && p == board[3].getValue() && p == board[6].getValue()) ||
				(p == board[1].getValue() && p == board[4].getValue() && p == board[7].getValue())  ||
				(p == board[2].getValue() && p == board[5].getValue() && p == board[8].getValue()))
				setWinner(p);
		else if ((p == board[0].getValue() && p == board[4].getValue() && p == board[8].getValue()) ||
			    (p == board[2].getValue() && p == board[4].getValue() && p == board[6].getValue()))
			setWinner(p);
		else
			setWinner(0);			
	}
	
	
	public int getWinner() {
		return winner;
	}

	public void setWinner(int winner) {
		this.winner = winner;
	}
	
}
